package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.UserBean;
import com.project.dto.UserDto;
import com.project.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 卢泓佚  414814103@qq.com on 2021/10/11
 * 远程调用接口
 */
@RequestMapping("/remote")
@RestController
@Api(tags = "远程调用测试接口")
public class RemoteController {
    @Autowired
    private IUserService userService;

    @GetMapping("/updateRiderStatus/{userCode}")
    public UserDto updateRiderStatus(@PathVariable("userCode") String userCode) {
        UserBean userBean = userService.updateRiderStatus(userCode);
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userBean, userDto);
        return userDto;
    }

    @GetMapping("/updateShopStatus/{userCode}")
    public UserDto updateShopStatus(@PathVariable("userCode") String userCode) {
        UserBean userBean = userService.updateShopStatus(userCode);
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userBean, userDto);
        return userDto;
    }

    @GetMapping("/findAllUser")
    public List<UserDto> findAllUser() {
        IPage<UserBean> page  = userService.findByItem(1, 1000, null, null , null , null);
        List<UserBean> beanList = page.getRecords();
        List<UserDto>  dtoList = new ArrayList<>();
        for (int i = 0; i < beanList.size(); i++) {
            UserDto dto = new UserDto();
            BeanUtils.copyProperties(beanList.get(i),dto);
            dtoList.add(dto);
        }
        return dtoList;
    }

}
